define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
	const controller = {
		index() {
			Table.api.init({
				extend: {
					index_url: 'depot/supplier/index',
					add_url: 'depot/supplier/add',
					edit_url: 'depot/supplier/edit',
					del_url: 'depot/supplier/del',
					table: 'depot_supplier',
				},
			});

			const table = $('#table');

			table.bootstrapTable({
				// 请求地址
				url: $.fn.bootstrapTable.defaults.extend.index_url,
				// 设置工具栏元素
				toolbar: '.toolbar',
				// 设置主键
				pk: 'id',
				// 排序字段
				sortName: 'createtime',
				// 默认排序方式
				sortOrder: 'desc',
				showExport: false,
				fixedColumns: true,
				fixedRightNumber: 1,
				// 渲染表格数据
				columns: [
					{ checkbox: true },
					{ field: 'id', title: __('Id'), sortable: true },
					{ field: 'name', title: __('Name'), operate: 'LIKE' },
					{ field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
					{ field: 'createtime_text', title: __('CreateTime'), operate: 'LIKE' },
					{ field: 'province_text', title: __('Province'), operate: 'LIKE' },
					{ field: 'city_text', title: __('City'), operate: 'LIKE' },
					{ field: 'district_text', title: __('District'), operate: 'LIKE' },
					{ field: 'address', title: __('Address'), operate: 'LIKE' },
					{
						field: 'operate',
						title: __('Operate'),
						table: table,
						events: Table.api.events.operate,
						formatter: Table.api.formatter.operate,
					},
				],
			});

			Table.api.bindevent(table);
		},
		add() {
			$('#c-Region').on('cp:updated', function () {
				var citypicker = $(this).data('citypicker');
				// console.log(citypicker)
				var code =
					citypicker.getCode('district') || citypicker.getCode('city') || citypicker.getCode('province');
				$('#code').val(code);
			});

			controller.api.bindevent();
		},
    edit() {
      $('#c-Region').on('cp:updated', function () {
				var citypicker = $(this).data('citypicker');
				// console.log(citypicker)
				var code =
					citypicker.getCode('district') || citypicker.getCode('city') || citypicker.getCode('province');
				$('#code').val(code);
      });
      
			controller.api.bindevent();
		},
		del() {
			controller.api.bindevent();
		},
		api: {
			// JS模块化的全局方法
			bindevent: function () {
				Form.api.bindevent($('form[role=form]'));
			},
		},
	};

	return controller;
});
